#include "groupchat.h"

GroupChat::GroupChat()
{

}
GroupChat::GroupChat(QString name, QString leader, QVector<Member> members)
:name(name), members(members), leader(leader)
{

}
// member
void GroupChat::AddMember(Member mb){
    members.append(mb);
}

void GroupChat::DelMember(Member mb){
    members.remove(members.indexOf(mb, 0));
}

void GroupChat::UpdMember(Member mb){
    // indexOf检索的是id是否匹配
    members.replace(members.indexOf(mb, 0), mb);
}

QVector<Member> GroupChat::GetMembers(){
    return members;
}

// admin
void GroupChat::AddAdmin(QString adm){
    if (administrators.size() < NUM_ADMIN)
        administrators.append(adm);
    else
        qDebug() << "管理员数量已达上限";
}

void GroupChat::DelAdmin(QString adm){
    administrators.remove(administrators.indexOf(adm, 0));
}

QString GroupChat::GetLeader(){
    return leader;
}

QVector<QString> GroupChat::GetAdmins(){
    return administrators;
}

QVector<QString> GroupChat::GetAllAdmins(){
    QVector<QString> allAdmins(administrators);
    allAdmins.append(leader);
    return allAdmins;
}
